package algorithm;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class leetcode_0763 {
    public List<Integer> partitionLabels(String s) {
        int len=s.length();
        int[] list=new int[len];
        for(int i=0;i<len;++i){
            for(int k=len-1;k>=i;--k){
                if(s.charAt(i)==s.charAt(k)){
                    list[i]=k;
                    break;
                }
            }
        }
        List<Integer> num=new LinkedList<>();
        int start=0;
        int end=list[0];
        while(start<len) {
            end=list[start];
            for (int i = start; i <= end; ++i) {
                if(end<list[i]) end=list[i];
            }
            num.add(end-start+1);
            start=end+1;

        }
        return num;
    }
}
